package com.twl.app.base.task;

import java.util.Date;
import java.util.Observable;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.twl.app.base.entity.SalDesKey;
import com.twl.common.constant.SalConstant;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;

@Transactional
@Component
public class DesKeyGenerator extends Observable {

	public Logger log = Logger.getLogger(this.getClass());

	@Autowired
	private WSHibernateDaoSupportProxy wsHibernateDaoSupportProxy;

	@Scheduled(cron = "0 0 3 * * *")
	public void generator() {
		SalDesKey salDesKey = new SalDesKey();
		salDesKey.setDesKey(UUID.randomUUID().toString().replace("-", "").substring(0, 12));
		salDesKey.setDesEffective(SalConstant.TRUE);
		salDesKey.setIsDelete(SalConstant.NOT_DELETE);
		salDesKey.setCreateTime(new Date());
		salDesKey.setCreator(SalConstant.GENERATOR);
		salDesKey.setModifyTime(new Date());
		salDesKey.setModifier(SalConstant.GENERATOR);
		try {
			wsHibernateDaoSupportProxy.saveOrUpdate(salDesKey);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info("生产密钥...");
		this.setChanged();
		this.notifyObservers(this);
	}

}
